package com.tes;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.text.ChangeableText;
import org.anddev.andengine.opengl.font.Font;
import org.anddev.andengine.opengl.font.FontFactory;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.ui.activity.BaseGameActivity;

import android.graphics.Color;

public class Main extends BaseGameActivity {
	private final int WIDTH = 320;
	private final int HEIGHT = 480;

	private BitmapTextureAtlas tHighScore;
	private Font mHighScore;

	private BitmapTextureAtlas texture;

	@Override
	public Engine onLoadEngine() {
		Camera camera = new Camera(0, 0, WIDTH, HEIGHT);
		Engine engine = new Engine(new EngineOptions(true,
				ScreenOrientation.PORTRAIT, new RatioResolutionPolicy(WIDTH,
						HEIGHT), camera));
		return engine;
	}

	@Override
	public void onLoadResources() {
		// set path
		FontFactory.setAssetBasePath("font/");
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");

		// set terxture size
		tHighScore = new BitmapTextureAtlas(128, 128,
				TextureOptions.REPEATING_BILINEAR_PREMULTIPLYALPHA);
		texture = new BitmapTextureAtlas(512, 512);

		// set texture
		mHighScore = FontFactory.createFromAsset(tHighScore, this,
				"Alpha Flight.ttf", 24, true, Color.RED);
		BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(texture,
				this, "scrum_tiled.png", 0, 0, 8, 4);

		// load texture
		mEngine.getTextureManager().loadTextures(tHighScore, texture);
		mEngine.getFontManager().loadFont(mHighScore);
	}

	@Override
	public Scene onLoadScene() {
		Scene scene = new Scene();

		// create object
		ChangeableText cText = new ChangeableText(200, 6, mHighScore, "XXX");

		// add object to sceane
		scene.attachChild(cText);

		// Timer timer = new Timer(cText, 300);
		// timer.start();

		return scene;
	}

	@Override
	public void onLoadComplete() {
		// TODO Auto-generated method stub

	}

}